﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;

namespace StudentLive.Common
{
    public static class Constants
    {
        public static string LanguageId = "LanguageId";

        public static string IsDatabaseInstalled = "IsDatabaseInstalled";

        public static string IsLoggedIn = "IsLoggedIn";

        public static FlowDirection GetFlowDirection()
        {
            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            string langId = (string)localSettings.Values[Constants.LanguageId];
            return langId == "en" ? FlowDirection.LeftToRight : FlowDirection.RightToLeft;
        }

        public static T FindChild<T>(this FrameworkElement element, string name)
        {
            DependencyObject dependencyObject = element;
            T result = default(T);

            if (dependencyObject != null)
            {
                int count = VisualTreeHelper.GetChildrenCount(dependencyObject);
                for (int i = 0; i < count; ++i)
                {
                    DependencyObject childObject = VisualTreeHelper.GetChild(dependencyObject, i);
                    FrameworkElement childElement = childObject as FrameworkElement;

                    if (childElement.GetType() == typeof(T) && childElement.Name == name)
                    {
                        result = (T)Convert.ChangeType(childElement, typeof(T));
                        break;
                    }

                    result = childElement.FindChild<T>(name);
                    if (result != null)
                    {
                        break;
                    }
                }
            }

            return result;
        }

        public enum ResourcesTypes
        {
            avi = 1,
            pdf = 2,
            mp3 = 3,
            png = 4,
            excel = 5,
            word = 6,
            ppt = 7
        }

        public enum NotificationTypes
        {
            Assignemts = 1,
            Grades = 2,
            Updates = 3,
        }

        public static string GetNotificationIconWithType(NotificationTypes type)
        {
            string res = string.Empty;
            switch (type)
            {
                case NotificationTypes.Assignemts:
                    res = "Assets\\assignment.png";
                    break;
                case NotificationTypes.Grades:
                    res = "Assets\\grade.png";
                    break;
                case NotificationTypes.Updates:
                    res = "Assets\\updates.png";
                    break;
                default:
                    break;
            }

            return res;
        }

        public static string GetResourceThumbnailWithResourceType(ResourcesTypes type)
        {
            string res = string.Empty;
            switch (type)
            {
                case ResourcesTypes.avi:   
                    break;
                case ResourcesTypes.pdf:
                    res = "Assets/pdf.png";
                    break;
                case ResourcesTypes.mp3:
                    break;
                case ResourcesTypes.png:
                    break;
                case ResourcesTypes.excel:
                    res = "Assets/excel.png";
                    break;
                case ResourcesTypes.word:
                    res = "Assets/word.png";
                    break;
                case ResourcesTypes.ppt:
                    res = "Assets/ppt.png";
                    break;
                default:
                    break;
            }

            return res;
        }

        public static void AdjustBackButtonTransform(Button backButton)
        {
            backButton.RenderTransformOrigin = new Windows.Foundation.Point(0.5, 0.5);
            if (GetFlowDirection() == FlowDirection.RightToLeft)
            {
                backButton.RenderTransform = new ScaleTransform() { ScaleX = -1 };
            }
            else
            {
                backButton.RenderTransform = new ScaleTransform() { ScaleX = -1 };
            }
        }

    }


}
